package com.luoye.unionlotto;

import java.io.*;
import java.util.List;

public class UnionlottoToFileWriter {
    private String dataDir="";

    public UnionlottoToFileWriter(String dataDir) {
        this.dataDir = dataDir;
    }
    public void write(List<Unionlotto> unionlottoList){
        //写文件
        BufferedWriter bufferedWriter=null;
        try {
            bufferedWriter=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(this.dataDir+"/data.txt")));
            for(Unionlotto unionlotto:unionlottoList){
                bufferedWriter.write(unionlotto.getDate()+":\t");
                for(String redBall:unionlotto.getRedBalls()){
                    bufferedWriter.write(redBall+"\t");
                }
                bufferedWriter.write("-\t"+unionlotto.blueBall);
                bufferedWriter.newLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(bufferedWriter!=null){
                try {
                    bufferedWriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
